import Http from "./Http";
import config from "../config/uri";
// const Http = new Http();
// const { get,post } = new Http

//经典电影
class Api extends Http {
  // 经典
  getNowPlayList({cityId, pageNum = 1, pageSize = 10}) {
    let url =  config.getNowPlayingFilmList +
      `?cityId=${cityId}&pageNum=${pageNum}&pageSize=${pageSize}`;
    return this.get(url);
  }
  //待映
  getComingFilmList({cityId, pageNum = 1, pageSize = 10}) {
    let url =
      config.getComingSoonFilmList +
      `?cityId=${cityId}&pageNum=${pageNum}&pageSize=${pageSize}`;
    return this.get(url);
  }
  // 经典详情
  getFilmInfo(filmId){
    let url = config.getFilmInfo + '?filmId=' +filmId
    return this.get(url)
  }
  //影院列表
  moreCinemas({offset,limit,cityId}){
    let url = config.moreCinemas + `?day=2020-12-06&offset=${offset}&limit=${limit}&cityId=${cityId}`
    return this.get(url);
  }
  // 品牌列表
  filterCinemas({ci=30,optimus_risk_level=71,optimus_code=10}){
    let url = config.filterCinemas + `?&ci=${ci}&optimus_risk_level=${optimus_risk_level}&optimus_code=${optimus_code}`
    return this.get(url);
  // 城市
  }
  async getCitiesInfo() {
    let ret = await this.get(config.getCitiesInfo)
    let cites = ret.data.cities

    // 首字母索引数组 [A,B,C,D,F]
    let indexList = []
    // 城市列表数据源
    let dataList = {}

    // 循环得到了索引数组
    for (let i = 65; i <= 90; i++) {
      indexList.push(String.fromCharCode(i))
    }

    // 循环索引数组，在数据源数组中查符合条件
    indexList.forEach(item => {
      // 大写变成小写
      let lowerChar = item.toLowerCase()
      let tmp = []
      tmp = cites.filter(val => {
        return lowerChar === val.pinyin.slice(0, 1)
      })
      if (tmp.length > 0) dataList[item] = tmp
    })

    return dataList;
  }
}
export default new Api;
